// @author ROGERIO

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.*;
public class implementacao extends UnicastRemoteObject implements interfacebd {
    public implementacao() throws RemoteException{
        super();
    }

    public Connection conexao() throws RemoteException{
        String url= "jdbc:mysql://localhost/agenda";
        String nome= "root";
        String senha="";
        String driver= "com.mysql.jdbc.Driver";
        
    try{
        Class.forName(driver).newInstance();
        Connection con = DriverManager.getConnection(url,nome,senha);
        return con;
    }
    catch(SQLException ex){
        System.out.println(ex.getMessage());
        return null;
    }
    catch(Exception e){
        return null;
    }
    }

    
    public String consulta(int sid) throws RemoteException {
        String s = null;
        try{
            Connection minhaconexao= conexao();
            Statement comando = minhaconexao.createStatement();
            ResultSet rs= comando.executeQuery ("select* from nomes where id = "+sid);
            while (rs.next()){
                s= (rs.getString(2));
            }
        minhaconexao.close();
        rs.close();
        comando.close();
        return s;
        }
    
catch (SQLException ex){
    
    System.out.println(ex.getMessage());
    return null;
}
catch (Exception e){ 
     System.out.println(e.getMessage());
      return null;
}           
    } 
    public String consultaemail(int sid) throws RemoteException {
       String s = null;
        try{
            Connection minhaconexao= conexao();
            Statement comando = minhaconexao.createStatement();
            ResultSet rs= comando.executeQuery ("select* from nomes where id = "+sid);
            while (rs.next()){
                s= (rs.getString(3));
            }
        minhaconexao.close();
        rs.close();
        comando.close();
        return s;
        }
    
catch (SQLException ex){
    
    System.out.println(ex.getMessage());
    return null;
}
catch (Exception e){ 
     System.out.println(e.getMessage());
      return null;
}           
    }

}
   
   